NAME=hexo
VERSION=alpine
IMAGE_URL=${NAME}:${VERSION}

all: build

build:
	docker build -t ${IMAGE_URL} .

init:
	@docker run -it --rm -v ${PWD}/hexo:/Hexo ${IMAGE_URL} \
		sh -c 'hexo init . ; \
		npm install ; \
		npm install hexo-deployer-git --save ; \
		npm install hexo-generator-sitemap --save ; \
		npm install hexo-generator-baidu-sitemap --save'

start:
	@docker run -it --rm -v ${PWD}/hexo:/Hexo ${IMAGE_URL} sh -c 'hexo g'
	@docker run -d --name hexo -p 80:4000  -v ${PWD}/hexo:/Hexo ${IMAGE_URL} sh -c 'hexo s'

update:
	@docker exec -it hexo sh -c 'hexo clean'
	@docker exec -it hexo sh -c 'hexo g'

clean:
	@docker rm -f hexo

help:
	@echo -e "\nUsage:"
	@echo -e "\tmake help\t# 帮助信息"
	@echo -e "\tmake build\t# 生成镜像"
	@echo -e "\tmake init\t# 初始化"
	@echo -e "\tmake start\t# 生成静态文件并启动"
	@echo -e "\tmake update\t# 生成静态文件"
	@echo -e "\tmake clean\t# 删除容器"

.PHONY: all build
